package com.aistar.service.impl;

import com.aistar.mapper.AncommMapper;
import com.aistar.mapper.AnswerMapper;
import com.aistar.mapper.MemberMapper;
import com.aistar.mapper.QuestionMapper;
import com.aistar.pojo.*;
import com.aistar.service.AncommService;
import com.aistar.service.AnswerService;
import com.aistar.service.MemberService;
import com.aistar.service.QuestionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class QuestionServiceImpl implements QuestionService {
    @Autowired
    private QuestionMapper questionMapper;
    @Autowired
    private AnswerService answerService;
    @Autowired
    private AncommService ancommService;
    @Autowired
    private MemberService memberService;
    @Autowired AnswerMapper answerMapper;

    @Override
    public Question getById(Integer id) {

           return questionMapper.selectByPrimaryKey(id);

    }


    //分页查询按照评论数量排序
    @Override
    public PageInfo<Question> getAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);

        QuestionExample example = new QuestionExample();
        example.setOrderByClause("que_annumber desc");

        List<Question> questionList = questionMapper.selectByExampleWithBLOBs(example);
        return new PageInfo<Question>(questionList);
    }

    //分页查询按照发布时间排序
    @Override
    public PageInfo<Question> getAllfromdate(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);

        QuestionExample example = new QuestionExample();
        example.setOrderByClause("que_time desc");

        List<Question> questionList = questionMapper.selectByExampleWithBLOBs(example);
        return new PageInfo<Question>(questionList);
    }

    @Override
    public int writeanswer(Answer answer) {

        int Y = answerMapper.insert(answer);
        return Y;
    }


}
